package cn.hesion.outputformat;
/**
 * ClassName: CustomOutputFormat <br/>
 * Description: <br/>
 * date: 2021/2/3 19:13<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @program: ClientDemo
 * @description:
 * @author: hesion
 * @create: 2021-02-03 19:13
 **/
public class CustomOutputFormat extends FileOutputFormat<Text, NullWritable> {
    @Override
    public RecordWriter<Text, NullWritable> getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException {
        FileSystem fs = FileSystem.get(context.getConfiguration());
        Path lagouPath = new Path("d:/lagou.log");
        Path otherPath = new Path("d:/other.log");
        //获取输出流
        FSDataOutputStream lagouOut = fs.create(lagouPath);
        FSDataOutputStream otherOut = fs.create(otherPath);

        return new CustomWriter(lagouOut, otherOut);
    }
}
